package com.ems.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class MvcWebConfig implements WebMvcConfigurer {

    @Value ("${filePath}")
    private String filePath;

    @Override
    public void addViewControllers (ViewControllerRegistry registry) {

    }

    @Override
    public void addInterceptors (InterceptorRegistry registry) {
        // 放行登录，注册，硬盘图片请求头
        String[] worksUrl = {"/user/login", "/user/register", "/img/**"};
        registry.addInterceptor ( new EmsInterceptor () ).addPathPatterns ( "/**" ).excludePathPatterns ( worksUrl );
    }

    @Override
    public void addResourceHandlers (ResourceHandlerRegistry registry) {
        // 放开对/img下所有资源
        registry.addResourceHandler ( "/img/**" ).addResourceLocations ( "file:" + filePath );
    }
}
